﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace RegressionAnalysis.Function
{
     class function
    {
        //计算x的平均值
        public static double Avarage1(double years)
        {
            double sum = 0;
            for (int i = 1; i <= years; i++)
            {
                sum += i;
            }
            return sum / years;
        }
        //计算Y的平均值
        public static double Avarage2(double[] GDP, double Basenumer)
        {
            double sum = 0;
            for (int i = 0; i < GDP.Length; i++)
            {
                double Y = Math.Log(GDP[i], Basenumer);
                sum += Y;
            }
            return sum / GDP.Length;
        }
        //计算b的大小
        public static double ValueOfb(double TheAverageOfx, double TheAverageOfY, double[] GDP, double Basenumer)
        {
            double molecule = 0, denominator = 0;
            for (int i = 0; i < GDP.Length; i++)
            {
                molecule += ((1 + i) - TheAverageOfx) * (Math.Log(GDP[i], Basenumer) - TheAverageOfY);
                denominator += ((1 + i) - TheAverageOfx) * ((1 + i) - TheAverageOfx);
            }
            return molecule / denominator;
        }
    }
}
